package company.beike;

import java.util.Scanner;

// 可以考虑通过加大数据范围来增加AC
public class BeiKe2A {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = sc.nextInt();
        for (int i = 0; i < count; i++) {
            long m = sc.nextInt();
            long n = sc.nextInt();
            System.out.println(helper(m, n));
        }
    }

    private static long helper(long a, long b) {
        long min = Math.min(a, b);
        for (long i = 2; i < min; i++) {
            if (a % i == 0 || b % i == 0)
                return i;
        }
        return min;
    }
}
